import 'sightable.dart';
import 'thing.dart';
import 'close_event.dart';
import 'command_item.dart';

class Bag extends Sightable {
  List<Thing> things = [];

  Bag() : super('背包') {
    add(CloseEvent());
  }

  String thingsDesc() {
    String desc = '';
    for (var item in things) {
      int index = things.indexOf(item);
      desc += '[${index+1}]${item.name} ';
    }
    return desc;
  }

  @override
  String optionCommandsDesc() {
    String result = thingsDesc();
    result += '\n' + super.optionCommandsDesc();
    return result;
  }

  @override
  CommandItem commandForIndexOrName(String value) {
    int intValue;
    try {
      intValue = int.parse(value);
    } catch (e) {
      intValue = -1;
    }
    int index = intValue-1;
    var result;
    if (index>=0 && index < things.length) {
      result = things[index];
    }
    if (result==null) {
      result = super.commandForIndexOrName(value);
    }
    return result;
  }
}